<?php

namespace IDock\Insurance\CHAC\Request;

use IDock\Insurance\CHAC\Response\GPolicyPaymentResponse;
use IDock\Printer\NonCar\NonCarInquirySinglePrinter;
use IDock\Visitor\PolicyPaymentVisitor;

class GPolicyPaymentRequest extends AllCHACRequest
{
    protected $route = 'chac/pay/payment';

    protected $response = GPolicyPaymentResponse::class;


    protected $urlTip = '支付接口';

    /*** @var  PolicyPaymentVisitor $visitor */
    protected $visitor;

    public function generate(): array
    {
        return [];
    }

    public function build(): string
    {
        $data = [
            'orderCoder' => $this->visitor->argc['orderNumber'] ?? '',
            'payAmt' => $this->visitor->argc['orderPrice'] ?? '',
            'businessType' => '1',
            'readFlag' => '1',
        ];

        if ($this->visitor->nonCarInquirySingle[0] ?? []) {
            /*** @var NonCarInquirySinglePrinter $nonCarInquirySinglePrinter */
            $nonCarInquirySinglePrinter = $this->visitor->nonCarInquirySingle[0];
            $data['acciAppPolicyNo'] = $nonCarInquirySinglePrinter->inquiryNo;
            $data['nvhlSuitCode'] = $nonCarInquirySinglePrinter->planCode;
            $data['payAmtnvhl'] = $nonCarInquirySinglePrinter->premium;
        }

        return $this->gateway.'/'.$this->route . '?' . http_build_query($data);
    }
}
